﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.API.Applications.Command.AquacultureCommand;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure;

namespace Traceability.API.Applications.CommandHandler.AquacultureCommandHandler
{
    public class HealthcareQueryCommandHandler : IRequestHandler<HealthcareQueryCommand, APIResult<List<Healthcare_Information>>>
    {
        private readonly IBaseRepository<Healthcare_Information> _healthcareRepository;

        public HealthcareQueryCommandHandler(IBaseRepository<Healthcare_Information> healthcareRepository)
        {
            _healthcareRepository = healthcareRepository;
        }

        public Task<APIResult<List<Healthcare_Information>>> Handle(HealthcareQueryCommand request, CancellationToken cancellationToken)
        {
            var res = _healthcareRepository.GetAll().Where(s => s.Batch == request.Batch&&!s.IsDeltede).AsNoTracking();

            APIResult<List<Healthcare_Information>> aPIResult = new APIResult<List<Healthcare_Information>>();
            aPIResult.Msg = "显示成功";
            aPIResult.Data = res.ToList();
            aPIResult.Code=EnumCode.Ok;

            return Task.FromResult(aPIResult);
        }
    }
}

